﻿using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace iOSClub.App.Desktop.Converters;

public class AirConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not string s) return value;
        if (!int.TryParse(s, out var i)) return s;
        string[] strings = ["优", "良", "轻微污染", "轻度污染", "中度污染", "重度污染"];
        var index = i / 50;
        index = index > 4 ? index - 1 : index;
        index = index > 5 ? 5 : index;
        return $"{strings[index]} {s}";
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value;
    }
}